package com.health.db.service.order.impl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.jdom2.JDOMException;

import com.health.db.dao.order.IZAdviceListDao;
import com.health.db.model.ZAdviceList;
import com.health.db.model.ZAdviceListTemp;
import com.health.db.service.order.IZAdviceListService;
import com.health.pay.tencent.common.XMLUtil;

public class ZAdviceListServiceImpl implements IZAdviceListService {
 
	
	private IZAdviceListDao zAdviceListDao;

	@Override
	public List<ZAdviceListTemp> selectSimpleForInit() {
		
		List<ZAdviceList> list = zAdviceListDao.selectSimpleForInit();
		
		int size = list.size();
		List<ZAdviceListTemp> returnList  = new ArrayList<ZAdviceListTemp>();
		ZAdviceListTemp zAdviceListTemp;
		ZAdviceList zAdviceList;
		for (int i = 0; i < size; i++) {
			 zAdviceListTemp = new ZAdviceListTemp();
			 zAdviceList= list.get(i);
			 zAdviceListTemp.setAdviceDesc(zAdviceList.getAdviceDesc());
			 zAdviceListTemp.setAdviceId(String.valueOf(zAdviceList.getMasterid()));
			
			 //xml格式 拆分
			 String data = zAdviceList.getAdviceData();
			 if (StringUtils.isNotEmpty(data)) {
			 try {
				 
				Map map = XMLUtil.doXMLParse(data);
				zAdviceListTemp.setDocId(map.get("AccepterID").toString());
				zAdviceListTemp.setDocImageUrl(map.get("Accepter_IconURL").toString());
				zAdviceListTemp.setDocName(map.get("Accepter_NAME").toString());
			} catch (JDOMException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			 }
			 returnList.add(zAdviceListTemp);
		}
		return returnList;
	}

	/**
	 * @return the zAdviceListDao
	 */
	public IZAdviceListDao getzAdviceListDao() {
		return zAdviceListDao;
	}

	/**
	 * @param zAdviceListDao the zAdviceListDao to set
	 */
	public void setzAdviceListDao(IZAdviceListDao zAdviceListDao) {
		this.zAdviceListDao = zAdviceListDao;
	}

	
}
